package bounce;

import java.awt.Color;

/**
 * Implementation of the Painter interface that does not actually do any
 * painting. A MockPainter implementation responds to Painter requests by
 * logging the request in a buffer. The contents of a MockPainter object's
 * log can be retrieved by a call to toString() on the MockPainter.
 * 
 * @author Ian Warren
 */
public class MockPainter implements Painter {
	// Internal log.
	private StringBuffer log = new StringBuffer();
	private Color colour = new Color(255, 255, 255); //default black
	private int xOffset = 0;
	private int yOffset = 0;

	/**
	 * Returns the contents of this MockPainter's log.
	 */
	public String toString() {
		return log.toString();
	}

	/**
	 * Logs the drawRect call.
	 */
	public void drawRect(int x, int y, int width, int height) {
		x += xOffset;
		y += yOffset;
		log.append("(rectangle " + x + "," + y + "," + width + "," + height + ")");
	}
	
	/**
	 * Logs the drawOval call.
	 */
	public void drawOval(int x, int y, int width, int height) {
		x += xOffset;
		y += yOffset;
		log.append("(oval " + x + "," + y + "," + width + "," + height + ")");
	}

	/**
	 * Logs the drawLine call.
	 */
	public void drawLine(int x1, int y1, int x2, int y2) {
		x1 += xOffset;
		y1 += yOffset;
		x2 += xOffset;
		y1 += yOffset;
		log.append("(line " + x1 + "," + y1 + "," + x2 + "," + y2 + ")");
	}
	
	public void fillRect(int x, int y, int width, int height) {
		x += xOffset;
		y += yOffset;
		log.append("(fill rect " + x + "," + y + "," + width + "," + height + ")");
	}
	
	public void setColor(Color c) {
		colour = c;
		log.append("(set colour " + colour.getRed() + "," + colour.getGreen() + "," + 
		colour.getBlue() + ")");
	}
	
	public Color getColor() {
		return colour;
	}
	
	public void drawCentredText(String message, int vertX, int vertY) {
		log.append("(draw text " + message + ")");
	}
	
	public void translate(int x, int y) {
		xOffset += x;
		yOffset += y;
	}
}